Skip to content

Fix device pixel ratio for tiff viewer#153

Merged
mvdbeek merged 2 commits intogalaxyproject:mainfrom
davelopez:tiffviewer_fix_device_pixel_ratio
Mar 12, 2026
Merged

Fix device pixel ratio for tiff viewer#153
mvdbeek merged 2 commits intogalaxyproject:mainfrom
davelopez:tiffviewer_fix_device_pixel_ratio

Conversation

@davelopez
Copy link
Copy Markdown
Contributor

@davelopez davelopez commented Mar 12, 2026

Summary of findings and fix (by Copilot):

  • Root cause: On macOS/Retina (devicePixelRatio=2), we set the canvas backing store to width2/height2 and then divided by dpr when computing fit/center. Panzoom computed transforms from the doubled backing size, causing the image to appear 4x larger with black padding.

  • Fix applied (packages/tiffviewer/src/ui-manager.ts): Draw at 1:1 logical pixels and stop dpr math in fit/center. Specifically:

    • Set canvas.width/height to the TIFF logical width/height (no dpr multiplier) and keep CSS width/height the same.
    • Removed context.scale(dpr, dpr) and dpr-based division when calculating sizes in fitImageToScreen and centerImageInContainer (use canvas.width/height directly).
    • This keeps Panzoom and layout in agreement across devices (Retina vs non-Retina).

Copy link
Copy Markdown

@kostrykin kostrykin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally. Running the master branch locally reproduces the issue described in galaxyproject/galaxy#22073. Running this PR instead fixes the issue.

@mvdbeek mvdbeek merged commit e5dc399 into galaxyproject:main Mar 12, 2026
14 checks passed
@davelopez davelopez deleted the tiffviewer_fix_device_pixel_ratio branch March 12, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants